package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.APWireDao;
import com.hongxun.modules.bss.entity.APWireEntity;
import com.hongxun.modules.bss.service.APWireService;



@Service("aPWireService")
public class APWireServiceImpl implements APWireService {
	@Autowired
	private APWireDao aPWireDao;
	
	@Override
	public APWireEntity queryObject(String guid){
		return aPWireDao.queryObject(guid);
	}
	
	@Override
	public List<APWireEntity> queryList(Map<String, Object> map){
		return aPWireDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return aPWireDao.queryTotal(map);
	}
	
	@Override
	public void save(APWireEntity aPWire){
		if(aPWire.getGuid()==null||aPWire.getGuid().equals("")) {

			aPWire.setGuid(UUID.randomUUID().toString());
		}
		aPWireDao.save(aPWire);
	}
	
	@Override
	public void update(APWireEntity aPWire){
		aPWireDao.update(aPWire);
	}
	
	@Override
	public void delete(String guid){
		aPWireDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		aPWireDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<APWireEntity> entities) {
		for (APWireEntity d : entities) {
			if (d.getPWDatastate().equals("删除")) {
				aPWireDao.delete(d.getGuid());
			} else {
				APWireEntity apWireEntity = aPWireDao.queryObject(d.getGuid());
				if (apWireEntity == null) {
					aPWireDao.save(d);
				} else {
					aPWireDao.update(d);
				}
			}
		}
	}
}
